<template>
	<view class="cu-modal" :class="showModal?'show':''">
		<view class="cu-dialog bg-white">
			<view class="cu-bar justify-end">
				<view class="content">选择推送模式</view>
				<view class="action" @tap="close">
					<text class="cuIcon-close text-red"></text>
				</view>
			</view>
			<view class="flex">
				<view @tap="pay(index)" v-for="(item, index) in list" :key="item.paycheckNum" class="flex-sub padding-xs">
					<view class="bg-gray text-left padding-bottom-xs">
						<view class="padding-top padding-left-sm">
							平台急聘 <text class="text-red">{{ item.topDesc }}</text> 天
						</view>
						<view class="padding-top-xs padding-left-sm">
							推送<text class="text-red">{{ item.pushGroupDesc }}</text>个驾驶员群
						</view>
						<view class="padding-top-xs padding-left-sm">
							推送<text class="text-red">{{ item.pushTimeDesc }}</text>
						</view>
						<view class="text-center margin">
							<button class="cu-btn bg-blue">支付 {{ item.paycheckNum }} 元</button>
						</view>
					</view>
				</view>
				<!--
				<view class="flex-sub padding">
					<view class="bg-gray text-left">
						<view class="padding-top padding-left">
							软件置顶 <text class="text-red"> 2天</text> 
						</view>
						<view class="padding-top-xs padding-left">
							推送 <text class="text-red"> 500</text> 驾驶员群
						</view>
						<view class="padding-top-xs padding-left">
							推送 <text class="text-red"> 一次</text> 
						</view>
						<view class="padding text-center">
							100元
						</view>
					</view>
				</view>
				<view class="flex-sub padding">
					<view class="bg-gray text-left">
						<view class="padding-top padding-left">
							软件置顶 <text class="text-red"> 3天</text> 
						</view>
						<view class="padding-top-xs padding-left">
							推送 <text class="text-red"> 1000</text>  驾驶员群
						</view>
						<view class="padding-top-xs padding-left">
							推送 <text class="text-red"> 一个月</text> 
						</view>
						<view class="padding text-center">
							300元
						</view>
					</view>
				</view>
				-->
			</view>
			<view class="padding text-center">
				费用支付后我们客服会第一时间联系您
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		name: "member",
		props: {
			showModal: {
				type: Boolean,
				value: false
			},
			id: {
				type: String,
				value: null
			},
		},
		data() {
			return {
				list: [{
					paycheckNum: 100,
					pushGroupDesc: "500",
					pushTimeDesc: "一次",
					topDesc: "2",
					paycheckId: 5
				}, {
					paycheckNum: 300,
					pushGroupDesc: "1000",
					pushTimeDesc: "一个月",
					topDesc: "3",
					paycheckId: 6
				}]
			}
		},
		// 组件生命周期
		created: function(e) {
			let _this = this
			this.baseRequest('api/driver/recharge/note', 'GET', {
				type: 1
			}, function(res, info) {
				_this.list = res
			})
		},
		watch: {},
		methods: {
			pay(index) {
				let type = '0';//0-手机自带浏览器H5支付  1-微信里打开支付， 2-原生安卓App支付
				var ua = window.navigator.userAgent.toLowerCase();
				if (ua.match(/micromessenger/i) == 'micromessenger') {
					type = '1';
				}
				let data = {
					paycheckNum: this.list[index].paycheckNum,
					paycheckId: this.list[index].paycheckId,
					type: type,
					orderType: 2,
					sourceID : this.id
				};
				let _this = this;
				var timestamp = Date.parse(new Date());
				uni.showLoading({
					title: '请稍候',
					mask: true
				})
				this.$emit('close', {})
				this.baseRequest('api/driver/recharge/gold', 'POST', data, function(res, info) {
					var ua = window.navigator.userAgent.toLowerCase();
					if (ua.match(/micromessenger/i) == 'micromessenger') {
						// 支付
						_this.$wx.wxpay(res, function(r) {
							if (r.errMsg == 'chooseWXPay:ok') {
								uni.showLoading({
									title: '请稍候'
								})
								setTimeout(()=>{
									window.location.href = res.mweb_url + '&time='+timestamp;
								}, 1000)
							} else {

							}
						});
					} else {
						if(typeof androlua == "undefined"){
							uni.showLoading({
								title: '请稍候'
							})
							setTimeout(()=>{
								uni.hideLoading();
								window.location.href = res.mweb_url + '&time='+timestamp;
							}, 1000)
						}else{
							window.location.href = res.mweb_url + '&time='+timestamp;
						}
					}
				});
			},
			close(item) {
				this.$emit('close', item)
			}
		}
	}
</script>
